#include <DFPlayer_Mini_Mp3.h>

//定义对应16进制数值的常量名
#define POWER   0xFD00FF       //电源
#define VOLUP   0xFD807F       //VOL+
#define STOP    0xFD40BF       //FUNC/STOP
#define PREV    0xFD20DF       //后退/上一曲
#define PAUSE   0xFDA05F       //暂停/播放
#define NEXT    0xFD609F       //前进/下一曲
#define DOWN    0xFD10EF       //下一页
#define VOLDOWN 0xFD906F       //VOL-
#define UP      0xFD50AF       //上一页
#define ZERO    0xFD30CF       //0
#define EQ      0xFDB04F       //EQ
#define REPT    0xFD708F       //ST/REPT
#define ONE     0xFD08F7       //1
#define TWO     0xFD8877       //2
#define THREE   0xFD48B7       //3
#define FOUR    0xFD28D7       //4
#define FIVE    0xFDA857       //5
#define SIX     0xFD6897       //6
#define SEVEN   0xFD18E7       //7
#define EIGHT   0xFD9867       //8
#define NINE    0xFD58A7       //9

int i = 50;
//int z = 0;
boolean a = true;

const int echoOne = 13;
const int trigOne = 12;

const int echoTow = 9;
const int trigTow = 8;

const int echoThree = 5;
const int trigThree = 4;

void setup() {
  Serial.begin(9600);
  mp3_set_serial(Serial);
  mp3_set_volume(i);

  pinMode(echoOne,INPUT);
  pinMode(trigOne,OUTPUT);

  pinMode(echoTow,INPUT);
  pinMode(trigTow,OUTPUT);

  pinMode(echoThree,INPUT);
  pinMode(trigThree,OUTPUT);

}

void loop() {
  digitalWrite(trigOne,LOW);
  delayMicroseconds(2);
  digitalWrite(trigOne,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigOne,LOW);
  float distance = pulseIn(echoOne,HIGH);
  distance = distance/58.0;
  Serial.print("第一个");
  Serial.print(distance);
  Serial.println("cm");

  digitalWrite(trigTow,LOW);
  delayMicroseconds(2);
  digitalWrite(trigTow,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigTow,LOW);
  float distanceTow = pulseIn(echoTow,HIGH);
  distanceTow = distanceTow/58.0;
  Serial.print("第二个");
  Serial.print(distanceTow);
  Serial.println("cm");

  digitalWrite(trigThree,LOW);
  delayMicroseconds(2);
  digitalWrite(trigThree,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigThree,LOW);
  float distanceThree = pulseIn(echoThree,HIGH);
  distanceThree = distanceThree/58.0;
  Serial.print("第三个");
  Serial.print(distanceThree);
  Serial.println("cm");
  delay(600);

  if(distance<10){
    mp3_play(1);
    delay(6000);
  }else{
    mp3_stop;
  }
  if(distanceThree<10){
    mp3_play(2);
    delay(6000);
  }else{
    mp3_stop;
  }
  
}
